<template>
  <div class="customerList">
    <el-card class="cardBox">
      <el-form class="s_form" :inline="true">
        <div class="left">
          <el-form-item>
            <div class="cardName">财务统计</div>
          </el-form-item>
        </div>
        <div class="right">
          <el-form-item>
            <el-date-picker size="small" v-model="dataForm.time" type="datetimerange" :picker-options="pickerOptions"
              range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right"
              value-format="timestamp" @change="getDataList">
            </el-date-picker>
          </el-form-item>
        </div>
      </el-form>
      <div class="content">
        <div class="item_cont">
          <div class="sum">
            <div>卖出车辆所得金额</div>
            <div class="number">{{dataForm2.finalPricess}}元</div>
          </div>
        </div>
        <div class="item_cont">
          <div class="sum">
            <div>购入车辆所耗费资金</div>
            <div class="number">{{dataForm2.guidePrices}}元</div>
          </div>
        </div>
        <div class="item_cont">
          <div class="sum">
            <div>利润</div>
            <div class="number">{{dataForm2.lirun}}元</div>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        time: []
      },
      dataForm2: {},
      pickerOptions: {
        shortcuts: [{
          text: '本月',
          onClick (picker) {
            let oneDayLong = 24 * 60 * 60 * 1000
            let now = new Date()
            let year = now.getFullYear()
            let monthStartDate = new Date(year, now.getMonth(), 1) // 当前月1号
            let nextMonthStartDate = new Date(year, now.getMonth() + 1, 1) // 下个月1号
            let days = (nextMonthStartDate.getTime() - monthStartDate.getTime()) / oneDayLong // 计算当前月份的天数
            let monthEndDate = new Date(year, now.getMonth(), days, 23, 59, 59)
            console.log([monthStartDate, monthEndDate])
            picker.$emit('pick', [monthStartDate, monthEndDate])
          }
        }, {
          text: '上个月',
          onClick (picker) {
            let oneDayLong = 24 * 60 * 60 * 1000
            let now = new Date()
            let year = now.getFullYear()
            let monthStartDate = new Date(year, now.getMonth() - 1, 1) // 当前月1号
            let nextMonthStartDate = new Date(year, now.getMonth(), 1) // 下个月1号
            let days = (nextMonthStartDate.getTime() - monthStartDate.getTime()) / oneDayLong // 计算当前月份的天数
            let monthEndDate = new Date(year, now.getMonth() - 1, days, 23, 59, 59)
            picker.$emit('pick', [monthStartDate, monthEndDate])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  activated () {
    this.getDataList()
  },
  methods: {
    // 获取数据
    getDataList () {
      this.$http.get('/cardeal/caiwu', {
        params: {
          startTime: (this.dataForm.time ? this.dataForm.time[0] : null),
          endTime: this.dataForm.time ? this.dataForm.time[1] : null
        }
      }).then(({ data: res }) => {
        let { code, msg, json } = res
        console.log(code, msg, json)
        if (code === 0) {
          this.dataForm2 = json
        }
        if (code !== 0) {
          this.$message.error(msg)
        }
      })
    }
  }
}
</script>

<style lang="scss">
.customerList {
  padding: 20px;
  .cardBox {
    width: 100%;
    min-width: 1100px;
    background-color: rgba(255, 255, 255, 1);
    margin-top: 15px;
    .s_form {
      display: flex;
      justify-content: space-between;
      .cardName {
        font-weight: bold;
        font-size: 18px;
      }
      .s_input {
        width: 100px;
      }
    }
    .content{
      display: flex;
      align-items: center;
      justify-content: space-around;
      width: 100%;
      margin-top: 20px;
      padding: 100px 0;
      .item_cont{
        text-align: center;
        flex: 3;
        border-right: 1px solid rgba(235, 235, 235, 1);
        color: rgba(0, 0, 0, 0.43);
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding: 0 25px;
        .sum{
          .number{
            font-size: 24px;
            color: rgba(0, 0, 0, 0.85);
            margin-top: 5px;
          }
        }
      }
    }
  }
}
</style>
